/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [FileMenu.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.notepad_V1.ui.file;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

/**
 * 文件菜单
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public abstract class FileMenu extends JMenu {

	private static final long serialVersionUID = -501715499477076767L;

	/** **********************文件菜单*********************** */
	private JMenuItem newFileItem; // 新建菜单项
	private JMenuItem openFileItem; // 打开菜单项
	private JMenuItem saveItem; // 保存菜单
	private JMenuItem saveAsItem; // 另存为菜单项
	private JMenuItem pageSettingItem; // 页面设置菜单项
	private JMenuItem printItem; // 打印菜单项
	private JMenuItem exitItem; // 退出菜单项

	/**
	 * 初始化文件菜单
	 * 
	 * @param menuName
	 */
	private void initFileMenu() {
		// 文件菜单
		this.setMnemonic(KeyEvent.VK_F); // 设置快捷键为Alt+F

		newFileItem = new JMenuItem("新建(N)"); // 新建菜单项
		newFileItem.setMnemonic('N'); // 设置激活键为N
		newFileItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
				InputEvent.CTRL_MASK)); // 设置快捷键为Ctrl+N
		this.add(newFileItem);

		openFileItem = new JMenuItem("打开(O)...");// 打开菜单项
		openFileItem.setMnemonic('O'); // 设置激活键为O
		openFileItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
				InputEvent.CTRL_MASK)); // 设置快捷键为Ctrl+O;
		this.add(openFileItem);

		saveItem = new JMenuItem("保存(S)"); // 保存菜单项
		saveItem.setMnemonic('S'); // 设置激活键为S
		saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
				InputEvent.CTRL_MASK)); // 设置快捷键为Ctrl+S
		this.add(saveItem);

		saveAsItem = new JMenuItem("另存为(A)..."); // 另存为菜单项
		saveAsItem.setMnemonic('A'); // 设置激活键为A
		this.add(saveAsItem);

		addSeparator(); // 添加分割线

		pageSettingItem = new JMenuItem("页面设置(U)...");// 页面设置菜单项
		pageSettingItem.setMnemonic('U'); // 设置激活键为U
		pageSettingItem.setEnabled(false);// 未实现功能, 不可用
		this.add(pageSettingItem);

		printItem = new JMenuItem("打印(P)..."); // 打印菜单项
		printItem.setMnemonic('P'); // 设置激活键为P
		printItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+P
		this.add(printItem);

		addSeparator(); // 添加分割线

		exitItem = new JMenuItem("退出(X)"); // 退出菜单项
		exitItem.setMnemonic('X'); // 设置激活键为X
		exitItem.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
				InputEvent.CTRL_MASK)); // 设置快捷键为Ctrl+Q
		this.add(exitItem);

	}

	public FileMenu(String menuName) {
		super(menuName);
		initFileMenu();
	}

	public FileMenu() {

	}

	public JMenuItem getNewFileItem() {
		return newFileItem;
	}

	public JMenuItem getOpenFileItem() {
		return openFileItem;
	}

	public JMenuItem getSaveItem() {
		return saveItem;
	}

	public JMenuItem getSaveAsItem() {
		return saveAsItem;
	}

	public JMenuItem getPageSettingItem() {
		return pageSettingItem;
	}

	public JMenuItem getPrintItem() {
		return printItem;
	}

	public JMenuItem getExitItem() {
		return exitItem;
	}

}
